#include<iostream>
#define maxn 20100
using namespace std;
int f[100005][100005];
int s1[100005];
int s2[100005];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s1[i];
    }
     for(int i=1;i<=n;i++){
        cin>>s2[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            f[i][j]=max(max(f[i][j-1],f[i-1][j]),f[i-1][j-1]+(s1[i]==s2[j]));
        }
    }
    cout<<f[n][n];
    return 0;
}